//
//  Info3ViewController.m
//  markmap
//
//  Created by 甘世清 on 2024/4/25.
//

#import "Info3ViewController.h"
#import <TTRangeSlider/TTRangeSlider.h>
#import <BRPickerView/BRPickerView.h>
#import "InfoMapViewController.h"
#import "Info4ViewController.h"
@interface Info3ViewController ()<TTRangeSliderDelegate>
@property (nonatomic , strong) TTRangeSlider * ttrange;
@property (nonatomic , strong) TTRangeSlider * ttrange2;
@property (nonatomic , strong) UILabel * shengaoLabel;
@property (nonatomic , strong) UILabel * tizhongLabel;
@property (nonatomic , strong) UILabel * addressLabel;
@property (nonatomic , strong) UILabel * shengriLabel;
@end

@implementation Info3ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.zx_navLeftBtn.hidden = YES;
    self.zx_navTitle = SQNSLocalString(@"基础资料");
    WS(weakSelf);
    NSString * valuue = [Manager SQ_stringForKey:@"userinfo_switch"];
    if (![valuue isEqualToString:@"1"]) {
        return;
    }
    [self zx_setRightBtnWithText:SQNSLocalString(@"跳过") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
        Info4ViewController * vc = [[Info4ViewController alloc]init];
        [weakSelf SQ_pushViewControllerFull:vc];
    }];
}

- (void)SQ_UIViewForSelfView{
    UIImageView * bg = [[UIImageView alloc]init];
    bg.image = SQGetImage(@"me背景");
    bg.contentMode = UIViewContentModeScaleAspectFill;
    [self.view addSubview:bg];
    [bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    UILabel * la = [[UILabel alloc]init];
    la.text = SQNSLocalString(@"身高:");
    la.font = FONT_REGULAR(16);
    la.textColor = UIColor.whiteColor;
    [self.view addSubview:la];
    [la mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(32);
            make.top.equalTo(self.zx_navBar.mas_bottom).offset(30);
    }];
    [self.view addSubview:self.shengaoLabel];
    [self.shengaoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view.mas_right).offset(-32);
            make.centerY.equalTo(la);
    }];
    [self.view addSubview:self.ttrange];
    [self.ttrange mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.mas_equalTo(SCREEN_WIDETH-32);
        make.top.equalTo(la.mas_bottom).offset(10);
        make.height.mas_equalTo(60);
    }];
    UILabel * la1 = [[UILabel alloc]init];
    la1.text = SQNSLocalString(@"体重:");
    la1.font = FONT_REGULAR(16);
    la1.textColor = UIColor.whiteColor;
    [self.view addSubview:la1];
    [la1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(32);
            make.top.equalTo(self.ttrange.mas_bottom).offset(40);
    }];
    [self.view addSubview:self.tizhongLabel];
    [self.tizhongLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view.mas_right).offset(-32);
            make.centerY.equalTo(la1);
    }];
    
    [self.view addSubview:self.ttrange2];
    [self.ttrange2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.mas_equalTo(SCREEN_WIDETH-32);
        make.top.equalTo(la1.mas_bottom).offset(10);
        make.height.mas_equalTo(60);
    }];
    
    
    UIView * oneView = [[UIView alloc]init];
    oneView.backgroundColor = SQHexColor(@"#FFFFFF", 0.2);
    oneView.layer.cornerRadius = 6;
    oneView.layer.masksToBounds = YES;
    [self.view addSubview:oneView];
    [oneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(SCREEN_WIDETH-50);
        make.height.mas_equalTo(52);
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.ttrange2.mas_bottom).offset(50);
    }];
    UILabel * la2 = [[UILabel alloc]init];
    la2.text = SQNSLocalString(@"生日:");
    la2.font = FONT_REGULAR(16);
    la2.textColor = UIColor.whiteColor;
    [oneView addSubview:la2];
    [la2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(oneView).offset(10);
            make.centerY.equalTo(oneView);
    }];
    [oneView addSubview:self.shengriLabel];
    [self.shengriLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(oneView.mas_right).offset(-10);
        make.centerY.equalTo(oneView);
    }];
    
    
    UIView * towView = [[UIView alloc]init];
    towView.backgroundColor = SQHexColor(@"#FFFFFF", 0.2);
    towView.layer.cornerRadius = 6;
    towView.layer.masksToBounds = YES;
    [self.view addSubview:towView];
    [towView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(SCREEN_WIDETH-50);
        make.height.mas_equalTo(52);
        make.centerX.equalTo(self.view);
        make.top.equalTo(oneView.mas_bottom).offset(20);
    }];
    UILabel * la3 = [[UILabel alloc]init];
    la3.text = SQNSLocalString(@"常住地:");
    la3.font = FONT_REGULAR(16);
    la3.textColor = UIColor.whiteColor;
    [towView addSubview:la3];
    [la3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(towView).offset(10);
            make.centerY.equalTo(towView);
    }];
    
    [towView addSubview:self.addressLabel];
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(towView.mas_right).offset(-10);
        make.centerY.equalTo(towView);
    }];
    
    UIButton * oneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    oneBtn.backgroundColor = UIColor.clearColor;
    [oneBtn addTarget:self action:@selector(SQ_oneButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [oneView addSubview:oneBtn];
    [oneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(oneView);
    }];
    
    UIButton * towBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    towBtn.backgroundColor = UIColor.clearColor;
    [towBtn addTarget:self action:@selector(SQ_towButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [towView addSubview:towBtn];
    [towBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(towView);
    }];
    
    HeaderView * xiayibu = [[HeaderView alloc]init];
    xiayibu.image = @"按钮背景";
    xiayibu.text = SQNSLocalString(@"下一步");
    xiayibu.colorString = @"#FFFFFF";
    [xiayibu.btn addTarget:self action:@selector(SQ_tijiaoButton) forControlEvents:UIControlEventTouchUpInside];
    xiayibu.font = FONT_MEDIUM(18);
    [self.view addSubview:xiayibu];
    [xiayibu mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.mas_equalTo(SCREEN_WIDETH-110);
        make.height.mas_equalTo(48);
        make.bottom.equalTo(self.view.mas_bottom).offset(-FootHeight);
    }];
    
    UserModel * model = [UserModel share];
    if (model.gender == 2) {
        //女
        self.ttrange.selectedMaximum = 165;
        self.shengaoLabel.text = @"165CM";
        self.ttrange2.selectedMaximum = 45;
        self.tizhongLabel.text = @"45KG";
    } else {
        //男和未知
        self.ttrange.selectedMaximum = 180;
        self.shengaoLabel.text = @"180CM";
        self.ttrange2.selectedMaximum = 65;
        self.tizhongLabel.text = @"65KG";
    }
   
}
-(void)SQ_tijiaoButton{
    if ([self.shengriLabel.text isEqualToString:@"未选择"]) {
        [YJProgressHUD showMsgWithoutView:@"请选择生日"];
        return;
    }
    if ([self.addressLabel.text isEqualToString:@"未选择"]) {
        [YJProgressHUD showMsgWithoutView:@"请选择常住地"];
        return;
    }
    
    [YJProgressHUD SQ_showMsgWithoutView:@""];
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[NSString stringWithFormat:@"%.f",self.ttrange.selectedMaximum] forKey:@"height"];
    [dic setObject:[NSString stringWithFormat:@"%.f",self.ttrange2.selectedMaximum] forKey:@"weight"];
    [dic setObject:self.shengriLabel.text forKey:@"birthday"];
    [dic setObject:self.addressLabel.text forKey:@"address"];
    [HttpTool post:Url5 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        Info4ViewController * vc = [[Info4ViewController alloc]init];
        [self SQ_pushViewControllerFull:vc];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
    
}
-(void)SQ_oneButtonClick{
    WS(weakSelf);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString* selectValue = [NSString SQ_GetoutYear:-30];
    NSString* minDate = [NSString SQ_GetoutYear:-100];
    NSString* maxDate = [NSString SQ_GetoutYear:-18];
    [BRDatePickerView showDatePickerWithMode:BRDatePickerModeYMD title:@"" selectValue:selectValue minDate:[dateFormatter dateFromString:minDate] maxDate:[dateFormatter dateFromString:maxDate] isAutoSelect:YES resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
        weakSelf.shengriLabel.text = selectValue;
        weakSelf.shengriLabel.textColor = UIColor.whiteColor;
    } resultRangeBlock:^(NSDate * _Nullable selectStartDate, NSDate * _Nullable selectEndDate, NSString * _Nullable selectValue) {
        
    }];
}
-(void)SQ_towButtonClick{
    InfoMapViewController * vc = [[InfoMapViewController alloc]init];
    vc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:vc animated:YES completion:nil];
    WS(weakSelf);
    [vc setAddressBlock:^(NSString * _Nonnull address) {
        weakSelf.addressLabel.text = address;
        weakSelf.addressLabel.textColor = UIColor.whiteColor;
    }];
}

/**
 * Called when the RangeSlider values are changed
 */
-(void)rangeSlider:(TTRangeSlider *)sender didChangeSelectedMinimumValue:(float)selectedMinimum andMaximumValue:(float)selectedMaximum{
    if (sender == self.ttrange) {
        self.shengaoLabel.text = [NSString stringWithFormat:@"%.fCM",selectedMaximum];
    } else {
        self.tizhongLabel.text = [NSString stringWithFormat:@"%.fKG",selectedMaximum];
    }
 
}
- (TTRangeSlider *)ttrange{
    if (!_ttrange) {
        _ttrange = [[TTRangeSlider alloc]init];
        _ttrange.maxValue = 230;
        _ttrange.minValue = 130;
        _ttrange.selectedMaximum = 170;
        _ttrange.hideLabels = YES;
        _ttrange.step = 1;
        _ttrange.lineHeight = 6;
        _ttrange.disableRange = YES;
        _ttrange.tintColor = UIColor.whiteColor;
        _ttrange.handleDiameter = 30;
        _ttrange.delegate = self;
        _ttrange.tintColorBetweenHandles = UIColor.whiteColor;
      
    }
    return _ttrange;
}
- (TTRangeSlider *)ttrange2{
    if (!_ttrange2) {
        _ttrange2 = [[TTRangeSlider alloc]init];
        _ttrange2.maxValue = 150;
        _ttrange2.minValue = 30;
        _ttrange2.selectedMaximum = 45;
        _ttrange2.hideLabels = YES;
        _ttrange2.step = 1;
        _ttrange2.lineHeight = 6;
        _ttrange2.disableRange = YES;
        _ttrange2.tintColor = UIColor.whiteColor;
        _ttrange2.handleDiameter = 30;
        _ttrange2.delegate = self;
        _ttrange2.tintColorBetweenHandles = UIColor.whiteColor;
      
    }
    return _ttrange2;
}
- (UILabel *)shengaoLabel{
    if (!_shengaoLabel) {
        _shengaoLabel = [[UILabel alloc]init];
        _shengaoLabel.font = FONT_MEDIUM(16);
        _shengaoLabel.textColor = UIColor.whiteColor;
        _shengaoLabel.text = @"170CM";
    }
    return _shengaoLabel;
}
- (UILabel *)tizhongLabel{
    if (!_tizhongLabel) {
        _tizhongLabel = [[UILabel alloc]init];
        _tizhongLabel.font = FONT_MEDIUM(16);
        _tizhongLabel.textColor = UIColor.whiteColor;
        _tizhongLabel.text = @"60KG";
    }
    return _tizhongLabel;
}
- (UILabel *)addressLabel{
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc]init];
        _addressLabel.font = FONT_REGULAR(14);
        _addressLabel.textColor = SQColor999999;
        _addressLabel.text = SQNSLocalString(@"未选择");
    }
    return _addressLabel;
}
- (UILabel *)shengriLabel{
    if (!_shengriLabel) {
        _shengriLabel = [[UILabel alloc]init];
        _shengriLabel.font = FONT_REGULAR(14);
        _shengriLabel.textColor = SQColor999999;
        _shengriLabel.text = SQNSLocalString(@"未选择");
    }
    return _shengriLabel;
}
@end
